package com.ruoyi.web.teacher;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.teacher.vo.TOptionVo;
import com.ruoyi.teacher.service.ITOptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 选项Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@Api(tags = "选项Controller")
@RestController
@RequestMapping("/teacher/option")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TOptionController extends BaseController {

    private final ITOptionService tOptionService;

    @ApiOperation("查询选项列表")
    @PreAuthorize("@ss.hasPermi('teacher:option:list')")
    @GetMapping("/list")
    public TableDataInfo<TOptionVo> list(TOptionVo entity) {
        return tOptionService.queryList(entity);
    }

    @ApiOperation("查询选项所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TOptionVo entity) {
        return AjaxResult.success("查询成功", tOptionService.queryAll(entity));
    }

    @ApiOperation("导出选项列表")
    @PreAuthorize("@ss.hasPermi('teacher:option:export')")
    @Log(title = "选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOptionVo entity) {
        List<TOptionVo> list = tOptionService.queryAll(entity);
        ExcelUtil<TOptionVo> util = new ExcelUtil<>(TOptionVo.class);
        util.exportExcel(response, list, "选项数据");
    }

    @ApiOperation("获取选项详细信息")
    @PreAuthorize("@ss.hasPermi('teacher:option:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tOptionService.queryById(id));
    }

    @ApiOperation("新增选项")
    @PreAuthorize("@ss.hasPermi('teacher:option:add')")
    @Log(title = "选项", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TOptionVo entity) {
        return toAjax(tOptionService.save(entity));
    }

    @ApiOperation("修改选项")
    @PreAuthorize("@ss.hasPermi('teacher:option:edit')")
    @Log(title = "选项", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TOptionVo entity) {
        return toAjax(tOptionService.updateById(entity));
    }

    @ApiOperation("删除选项")
    @PreAuthorize("@ss.hasPermi('teacher:option:remove')")
    @Log(title = "选项", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tOptionService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
